package com.lzw.service.impl.dormitoryAdmin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lzw.mapper.dormitoryAdmin.AnnounceMapper;
import com.lzw.pojo.Announcement;
import com.lzw.service.dormitoryAdmin.AnnounceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class AnnounceServiceImpl implements AnnounceService {
    @Autowired
    private AnnounceMapper announcementMapper;

    @Override
    public List<Announcement> list(Integer pageNum, Integer pageSize, LocalDate datePosted, String postedBy) {
        PageHelper.startPage(pageNum,pageSize);
        List<Announcement> list = announcementMapper.list(datePosted, postedBy);
        Page<Announcement> announcements = (Page<Announcement>) list;
        return announcements;
    }

    @Override
    public void add(Announcement announcement) {
        announcement.setDatePosted(LocalDate.now());
        announcementMapper.add(announcement);
    }
}
